package com.itheima.jianbing;

public class Cooker implements Runnable {
    @Override
    public void run() {
        //while(true) 死循环 条件 当没有数量时  下班
        while (Desk.count>0) {
            //判断是否有煎饼
            synchronized (Desk.obj) {
                if (Desk.flag) {  //有  等着
                    try {
                        Desk.obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {
                    //没有   做一个
                    System.out.println("大爷正在做一个煎饼");

                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("做好了");
                    //修改煎饼的状态
                    Desk.flag=true;
                    //叫人吃
                    Desk.obj.notifyAll();
                }
            }


        }


    }
}
